from decimal import Decimal
import string
import os

from error import *

def polygons(config, filename, args):
	if not config.has_option("envisat", "cqfd_base"):
		raise ConfigError("[envisat]/cqfd_base not present in config")
	cqfd_base = config.get("envisat", "cqfd_base")
	cqfd_bin = os.path.join(cqfd_base, "bin")
	system, hostname, kernel, build, march = os.uname()
	polygon_bin = "polygon." + system.lower() + "." + march
	polygon = os.path.join(cqfd_bin, polygon_bin)
	if "CQFD_DICTIONARY_PATH" not in os.environ:
		os.environ["CQFD_DICTIONARY_PATH"] = os.path.join(cqfd_base, "dd")
	fp = os.popen("%s %s %s" % (polygon, filename, args))
	result = fp.read()
	fp.close()
	return result
